package com.xjggb.createThread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CreateThread {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyJob myJob = new MyJob();
        myJob.start();

        MyJob myJoc = new MyJob();
        myJoc.start();

        MyJon myJon = new MyJon();
        FutureTask<String> stringFutureTask = new FutureTask<>(myJon);
        Thread thread = new Thread(stringFutureTask);
        thread.start();
        System.out.println("stringFutureTask.get() = " + stringFutureTask.get());

        new Thread(()->{
            for (int i = 0; i <20 ; i++) {
                System.out.println("i = I" + i);
            }
        }).start();




    }
}
/*
* 创建线程的三种方式
* */

class  MyJob extends Thread{
    @Override
    public void run() {
        for (int i = 0; i <100 ; i++) {
            System.out.println("true = " + i);
        }
    }
}

class  MyJoc implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i <100 ; i++) {
            System.out.println("true = " + i);
        }
    }
}


class  MyJon implements Callable<String> {

    @Override
    public String call() throws Exception {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < 100; i++) {
            
            stringBuilder.append(i);
        }
        return stringBuilder.toString();
    }
}
